<!-- 政策详情  -->
<template>
  <view class="container screen-width">
    <view class="main_content">
      <view>
        <view class="main_head">
          <view class="title">{{detailData.title}}</view>
          <view class="time_text">
            日期: {{detailData.createTime || '--'}} 来源：{{detailData.nickName || '--'}}
            <span
              v-if="detailData.whetherCanExport === 1"
              @tap="toExport(detailData.policyId)"
            >{{downName===1?'符合申报条件企业名单':'符合下一批申报企业名单'}}</span>
          </view>
        </view>
        <view class="main_body">
          <view class="main_item" v-html="detailData.content"></view>
          <view class="readNum">
            <view class="readNum_L">
              <span>阅读量:{{detailData.pageViewCount || '0'}}</span>
            </view>
          </view>
        </view>
      </view>
    </view>
    <Festival></Festival>
  </view>
</template>

<script>
import { newsDetail } from "../../util/api/newsList.js";
import { isWeixin, wxShareConfig } from "util/wx.js";
import { fileUrl } from "../../util/api";
import {
  whetherDownload,
  whetherCanExport,
  getPolicyCompanyUrl
} from "../../util/api/policy.js";
export default {
  data() {
    return {
      id: "",
      detailData: {},
      hcontent: "",
      downName: 1 // 下载名单 2公示：下一批符合条件可申报企业名单 1通知：符合申报条件企业名单
    };
  },

  onLoad(e) {
    this.id = e.id;
  },
  mounted() {
    this.getNewsDetail();
  },
  //方法集合
  methods: {
    getNewsDetail() {
      newsDetail(this.id).then(res => {
        this.detailData = res.result;
        // 判断标题关键字
        if (this.detailData.title.includes("公示")) {
          this.downName = 2;
        } else {
          this.downName = 1;
        }
        if (this.detailData.title) {
          if (isWeixin()) {
            this.initShareConfig();
          }
        }
      });
    },
    postMessageToMini() {
      let _this = this;
      let shareInfo = {
        link:
          "/pages/topage/index?redirect=" +
          encodeURIComponent(window.location.href)
      };
      if (window.UniAppJSBridge) {
        //向uniapp传值
        uni.webView.postMessage({
          data: shareInfo
        });
      } else {
        document.addEventListener("UniAppJSBridgeReady", function() {
          //向uniapp传值
          uni.webView.postMessage({
            data: shareInfo
          });
        });
      }
    },
    initShareConfig() {
      let _this = this;
      let windowurl = window.location.href.split("#")[0];
      uni.request({
        url: "https://oldm.51bmj.cn/WeiXin/GetClientSign", //仅为示例，并非真实接口地址。
        data: {
          rawUrl: windowurl
        },
        dataType: "json",
        header: {
          "X-Requested-With": "XMLHttpRequest"
        },
        method: "GET",
        success: res => {
          if (res.statusCode == 200) {
            let { data } = res;
            let shareInfo = {
              title: _this.detailData.title,
              desc: "政策尽知 红利尽享",
              link: window.location.href
            };
            wxShareConfig(this.$wx, data, shareInfo);
          }
        }
      });
    },
    toExport(policyId) {
      whetherCanExport().then(res => {
        if (res.code === 10001) {
          uni.showToast({
            title: "您还没有登录，请登录后操作",
            duration: 2000,
            icon: "none"
          });
          setTimeout(() => {
            uni.setStorageSync("pageUrl", window.location.href);
            uni.navigateTo({
              url: "/pages/login/index"
            });
          }, 2000);
        } else if (res.code === 10006) {
          uni.showModal({
            title: "提示",
            content: "可下载数量已满",
            confirmText: "升级会员",
            success: function(res) {
              if (res.confirm) {
                // 升级会员
                uni.navigateTo({
                  url: "/pages/VIP/index"
                });
              }
            }
          });
        } else if (res.code === 200) {
          whetherDownload({ source: "1", policyId: policyId });
          getPolicyCompanyUrl({ policyId }).then(res => {
            if (res.code == 200 && res.result) {
              window.location.href = fileUrl + res.result;
            } else {
              uni.showToast({
                title: "企业名单未生成，请稍后重试！",
                duration: 2000,
                icon: "none"
              });
            }
          });
        }
      });
    }
  }
};
</script>
<style>
body {
  user-select: text;
}
</style>
<style lang="less" scoped>
/deep/ img {
  max-width: 350px;
}
//@import url(); 引入公共css类
.main_content {
  background-color: #fff;
  user-select: text;
  .main_head {
    padding: 0 30rpx 50rpx;
    background-color: #fff;
    border-bottom: 1rpx solid #ccc;
    margin-bottom: 54rpx;
    user-select: text;
    .title {
      padding: 40rpx 0;
      font-size: 20px;
      color: #333;
      font-weight: 700;
    }

    .subTitle {
      max-width: 690rpx;
      height: 80rpx;
      display: flex;
      align-items: center;
      background-color: #eef0fc;
      justify-content: space-around;
      font-size: 14px;
      color: #333;
      border-radius: 10rpx;

      span {
        display: flex;
        align-items: center;
        justify-content: space-around;
        font-size: 14px;
        width: 120rpx;
        height: 48rpx;
        background-color: #1678ff;
        border-radius: 10rpx;
        color: #fff;

        image {
          width: 8px;
          height: 8px;
          // font-size: 0;

          // margin-top:30rpx;
        }
      }
    }

    .time_text {
      margin-top: 30rpx;
      color: #aaaaaa;
      height: 60rpx;
      font-size: 13px;

      span {
        color: red;
        font-size: 32rpx;
        margin-left: 20rpx;
      }
    }
  }

  .main_body {
    padding: 0 30rpx;
    user-select: text;
    box-sizing: border-box;
    overflow: scroll;
    .main_item {
      min-height: 626rpx;
      user-select: text;
      font-size: 16px;
      .items {
        padding-left: 20rpx;
        height: 80rpx;
        display: flex;
        align-items: center;
        font-size: 15px;
        font-weight: 700;
        background-color: #e9f3ff;
        color: #227fff;
      }

      .content {
        font-size: 14px;
        margin: 20rpx auto;
        word-wrap: break-word;
        white-space: pre-wrap;
      }
    }

    .readNum {
      padding: 60rpx 0;
      color: #ccc;
      font-size: 13px;
      display: flex;
      border-bottom: 1rpx solid #f0f0f0;

      .readNum_L {
        display: flex;
        justify-content: flex-start;
        align-items: center;

        text {
          display: flex;
          align-items: center;
          margin-right: 30rpx;
          color: #ccc;
        }
      }

      .readNum_R {
        margin-left: 10rpx;

        a {
          font-size: 14px;
          color: #1678ff;
        }
      }

      view.shareBtn {
        margin-left: 30rpx;
        display: flex;
        align-items: center;
        position: relative;
        height: 30rpx;

        button {
          position: absolute;
          left: 25rpx;
          opacity: 0;
          top: 0;
        }
      }

      image {
        width: 36rpx;
        height: 36rpx;
        margin-left: 20rpx;
        // margin-top:10rpx;
      }
    }
  }

  .makeCard {
    margin: 20rpx auto;

    .userCard {
      border-radius: 10rpx;
      width: 690rpx;
      height: 385rpx;
      padding: 0 40rpx;
      background-size: contain;
      background-image: url(../../static/userCard/card_bg.png);

      .userInfo {
        padding: 40rpx 0rpx;
        display: flex;
        align-items: center;
        justify-content: space-between;

        .user_portrait {
          display: flex;
          align-items: center;

          image {
            width: 120rpx;
            height: 120rpx;
          }

          .message {
            margin-left: 20rpx;

            .company_name {
              color: #aaaaaa;
              font-size: 11px;
            }

            .person {
              .name {
                color: #1f7dff;
                font-size: 36rpx;
              }

              .position {
                color: #6e6e6f;
                margin-left: 30rpx;
              }
            }

            .synopsis {
              color: #aaaaaa;
              font-size: 12px;
            }
          }
        }

        .goto {
          image {
            width: 16rpx;
            height: 24rpx;
          }
        }
      }

      .user_address {
        .userphone {
          span {
            color: #333333;
            font-size: 12px;
            margin-right: 20rpx;

            image {
              margin-right: 20rpx;
              width: 18rpx;
              height: 22rpx;
            }
          }
        }

        .address {
          color: #333333;
          font-size: 12px;

          image {
            margin-right: 20rpx;
            width: 18rpx;
            height: 22rpx;
          }
        }
      }
    }
  }
}

.wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}
</style>
